|
|
|
Let's come back to our class
Point. Its interface starts with the public section where we define four
methods. Two for each coordinate to set and get its value. The
|
|
set methods are only
declared. Their actual functionality is still to be defined. The get methods
have a function body: They are defined within the class or, in other
|
|
words, they are inlined
methods.
|
|
This type of method
definition is useful for small and simple bodies. It also improve
performance, because bodies of inlined methods are “copied'' into the code
|
|
wherever a call to such a
method takes place.
|
|
On the contrary, calls to
the set methods would result in a ``real'' function call. We define these
methods outside of the class declaration. This makes it necessary, to
indicate to which class a method definition belongs to. For example, another
class might just define a method setX() which is quite different from that of
Point. We
|
|
must be able to define the
scope of the definition; we therefore use the scope operator “::'‘.
|
|
Here we define method setX()
(setY()) within the scope of class Point. The object apoint can use these
methods to set and get information about itself:
|
|
|